import * as actionTypes from "./constants";

import { getSongStyle, getTopPlaylist } from "@/services/song";

const getSubAction = (res) => ({
  type: actionTypes.GETSONGSUB,
  sub: res.sub,
});

const getCategories = (res) => ({
  type: actionTypes.GETSONGCATEGORIES,
  categories: res.categories,
});

const getAll = (res) => ({
  type: actionTypes.GETSONGSTYLEALL,
  all: res.all,
});

const getTopPlaylistAction = (res) => ({
  type: actionTypes.GETTOPPLAYLISTACTION,
  playlists: res,
});

export const getSongStyles = () => {
  return (dispatch) => {
    getSongStyle().then((res) => {
      dispatch(getSubAction(res));
      dispatch(getCategories(res));
      dispatch(getAll(res));
    });
  };
};

export const getTopPlaylistAxios = (cat, limit, offset, order) => {
  return (dispatch) => {
    getTopPlaylist(cat, limit, offset, order).then((res) => {
      dispatch(getTopPlaylistAction(res));
    });
  };
};
